package br.com.portalecbahia.customize;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import br.com.portalecbahia.R;
import br.com.portalecbahia.model.Media;

import com.raptureinvenice.webimageview.image.WebImageView;

public class VideoListAdapter extends BaseAdapter {
    
	private Context context;

    private List<Media> listMedia;
   
    public VideoListAdapter (Context context, List<Media> listMedia){
        this.context = context;
        this.listMedia = listMedia;
    }
    
	public int getCount() {
		// TODO Auto-generated method stub
		return  listMedia.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return listMedia.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
        // Get actual object
		Media media = listMedia.get(position);
		 // on View
        LayoutInflater inflater = (LayoutInflater)
            context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.item_list_video , null);
        
        // Title Item
        TextView textTitle = (TextView)view.findViewById(R.id.titleTX);
        if(media.getTitle()!=null){
        	textTitle.setText(media.getTitle());
        }else{
        	textTitle.setText("");
        }
        // Date Item
        TextView textDate = (TextView)view.findViewById(R.id.dateTX);
        if(media.getDate()!=null){
        	textDate.setText(media.getDateFormat());
        }else{
        	textDate.setText("");
        }

    	WebImageView myImage = (WebImageView)view.findViewById(R.id.videoIMG);

        if(media.getUrlImage()!=null && !"".equals(media.getUrlImage())){
        	WebImageView.setDiskCachingDefaultCacheTimeout(60 * 60* 24*30); // 1 month expiration
        	myImage.setImageWithURL(context, media.getUrlImage());
        }
        
        // Content Item
        TextView textTime = (TextView)view.findViewById(R.id.timeTX);
        if(media.getTime()!=null){
        	textTime.setText(media.getTime());
        }else{
        	textTime.setVisibility(View.INVISIBLE);
        }

        ImageView imageArrow = (ImageView)view.findViewById(R.id.arrowIMG);
        if(media.getId()==null){
        	imageArrow.setVisibility(View.INVISIBLE);
        	myImage.setBackgroundColor(Color.WHITE);
        }else{
        	imageArrow.setVisibility(View.VISIBLE);	
        }
        
        
        return view;
	}

	
	 
	
	

}
